package com.jdd.enterprise.api.controller.admin;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.jdd.enterprise.api.dto.ApiRequest;
import com.jdd.enterprise.api.dto.PageRequest;
import com.jdd.enterprise.api.vo.ApiResponse;
import com.jdd.enterprise.api.vo.DishSpuVO;
import com.jdd.enterprise.api.vo.PageResponse;
import com.jdd.enterprise.api.vo.SpuAndSkuVO;
import com.jdd.enterprise.domain.entity.DishCategory;
import com.jdd.enterprise.domain.entity.DishSku;
import com.jdd.enterprise.domain.entity.DishSpu;
import com.jdd.enterprise.domain.entity.DishSpuDTO;
import com.jdd.enterprise.domain.mapper.DishSpuMapper;
import com.jdd.enterprise.domain.service.DishSpuService;
import com.jdd.enterprise.util.PageUtil;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.checkerframework.checker.guieffect.qual.UI;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("dishSpu")
@CrossOrigin
public class DishSpuController {
    @Autowired
    private DishSpuMapper dishSpuMapper;


    @Autowired
    private DishSpuService dishSpuService;




    /*
    分页查询列表
     */
@PostMapping("spuList")
    public ApiResponse<PageResponse<DishSpuVO>>  spuList(@RequestBody PageRequest<DishSpu> request){



    PageResponse<DishSpuVO> dishSpuVOPageResponse = dishSpuService.spuList(request);



    return ApiResponse.success(dishSpuVOPageResponse);

}

/*
菜品排序
 */
@PostMapping("sorting")
    public void sorting (@RequestBody ApiRequest<Map<Integer , Integer>> request){
    dishSpuService.sorting(request.getParam());
}







@PostMapping("createDishSpu")
    public void createDishSpu(@RequestBody ApiRequest<DishSpuDTO> request){

    dishSpuService.createDishSpu(request.getParam());

}

@PostMapping("ceshi")
    public ApiResponse<List<DishSpu>> ceshi(){


    LambdaQueryWrapper<DishSpu> wrapper = Wrappers.lambdaQuery(DishSpu.class);


    List<DishSpu> dishSpus = dishSpuMapper.selectList(wrapper);


    return ApiResponse.success(dishSpus);
}



@PostMapping("spuAndSku")
    public ApiResponse<PageResponse<SpuAndSkuVO>>  spuAndSku (@RequestBody  PageRequest<DishSpu> request){


    List<SpuAndSkuVO> spuAndSkuVOS = dishSpuService.spuAndSku(request);


    PageResponse<SpuAndSkuVO> page = PageUtil.createPage(request.getCurrentPage(), request.getPageSize());

    PageUtil.refreshData(page, (long) spuAndSkuVOS.size(),spuAndSkuVOS);





    return ApiResponse.success(page);
}





@PostMapping("showTakeoutBoxes")



    public void showTakeoutBoxes(){
    dishSpuService.showTakeoutBoxes();

}

}




















































